<?php
class Pektis {
	public $login;
	public $onoma;
	public $email;

//na mpoun ta sxolia
	public function __construct($login = NULL, $kodikos = NULL) {
		global $globals;

		$this->login = NULL;
		$this->onoma = NULL;
		$this->email = NULL;

		if (!isset($login)) {
			return;
		}
			
		$query = "SELECT * FROM `pektis` WHERE `login` = '" .
			$globals->asfales($login) . "'";
		if (isset($kodikos)) {
			$query .= " AND `kodikos` = '" . $globals->asfales($kodikos) . "'";
		}
		$query .= " LIMIT 1";

		$result = $globals->query($query);
		$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
		if ($row === FALSE) {
			return;
		}

		mysqli_free_result($result);
		$this->login = $row['login'];
		$this->onoma = $row['onoma'];
		$this->email = $row['email'];
	}

	public function set_poll() {
		global $globals;

		$query = "UPDATE `pektis` SET `poll` = NOW() WHERE `login` = '" .
			$this->login . "'";
		$globals->query($query);

		$query = "UPDATE `partida` SET `poll` = NOW() WHERE (`pektis1` = '" .
			$this->login . "') OR (`pektis2` = '" . $this->login .
			"') OR (`id` IN (SELECT `partida` FROM `theatis` WHERE " .
			"`pektis` = '" . $this->login . "'))";

		$globals->query($query);
	}
}
?>
